const vm = require('vm');

global.aa = 'abc';

const context = {
  animal: 'cat',
  count: 2
};

const obj = {};

const script = new vm.Script('obj.aa = 234; count += 1; name = "kitty";');

vm.createContext(context);
for (let i = 0; i < 10; ++i) {
  script.runInContext(context);
}

// vm.runInNewContext('this.constructor.constructor("return process")().exit()');
// console.log('Never gets executed.');

console.log(context);
// Prints: { animal: 'cat', count: 12, name: 'kitty' }
console.log(global.aa);


